package org.mifos.boss.domainmodel.standalone;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.StringTokenizer;

public class MifosTablePopulatorMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String strFile = "C:/FileIO/example.csv";
		try{
			//create BufferedReader to read csv file
			BufferedReader br = new BufferedReader( new FileReader(strFile));
			String strLine = "";
			StringTokenizer st = null;
			int lineNumber = 0;
			String DELETE_SQL = "";

			//read comma separated file line by line
			while( (strLine = br.readLine()) != null){
				lineNumber++;
				//break comma separated line using ","
				st = new StringTokenizer(strLine, ",");
				getInsertSql(st);
			}
		}catch(Exception e){
			System.out.println("Exception while reading csv file: " + e);			
		}
	}

	private static MifosTableValueObject getInsertSql(StringTokenizer st) {
		MifosTableValueObject obj = new MifosTableValueObject();

		if(st.hasMoreTokens()){
			obj.setMemberId(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setMemberName(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setOfficeName(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setCenterId(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setCenterName(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setGroupId(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setGroupName(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setMeetingDate(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setLoanOfficerName(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setLoanBalance(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setLoanDisbursed(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setLoanDue(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setLoanFees(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setTotalLoanBalance(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setTotalLoanDisbursed(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setTotalLoanDue(st.nextToken());
		}
		if(st.hasMoreTokens()){
			obj.setTotalLoanFees(st.nextToken());
		}
		return obj;
	}
}
